package com.qing.design.patterns.observer.example.editor;

import com.qing.design.patterns.observer.example.publisher.EventManager;

import java.io.File;

/**
 * 具体发布者，由其他对象追踪  编辑
 */
public class Editor {

    public EventManager events;

    private File file;

    public Editor() {
        this.events=new EventManager("open","save");
    }

    public void openFile(String filePath){
        this.file=new File(filePath);
        events.notify("open",file);
    }

    public void saveFile() throws Exception {
        if(this.file!=null){
            events.notify("save",file);
        }else{
            throw  new Exception("请先打开一个文件");
        }
    }
}
